<?php
declare(strict_types=1);

namespace App\Dao;

use App\Model\Role;

class RoleDao
{

    use \App\Lib\RbacTrait;
    
    //通过条件搜索权限
    public function searchByWhere($where = []){
        return Role::query()->where($where)->get()->toArray();
        
    }

    //通过条件搜索单一条权限
    public function searchByWhereFirst($where){
        return Role::query()->where($where)->first();
        
    }

    //通过in查找权限id
    public function searchIdByIn($where){
        return Role::query()->whereIn('parent_id',$where)->pluck('id')->toArray();
        
    }

    //通过in查找权限
    public function searchDataByIn($where){
        return Role::query()->whereIn('id',$where)->get()->toArray();
        
    }

    //通过in删除权限
    public function delDataByIn($where){
        return Role::query()->whereIn('id',$where)->delete();
        
    }


    //通过条件搜索分页角色
    public function searchByWherePage($pageSize,$where = []){
        $data = Role::where($where)->paginate(intval($pageSize),['*'],'page')->toArray();
        return $data['data'];
    }


    //通过条件统计数量角色
    public function countByWhere($where = []){
        return Role::query()->where($where)->count();
        
    }

    //找出用户所有的角色
    public function allRoleByWhere($where = []){
        return Role::query()->where($where)->get()->toArray();
        
    }

    //添加角色
    public function add($data)
    {
        return Role::create($data);
    }
    //更新角色
    public function update($where,$data)
    {
        return Role::query()->where($where)->update($data);
    }
    //找出角色的所有权限id
    public function rolePermidByRoleid($role_id)
    {
        return static::permissionIdByRoleid($role_id);

    }

    
}
